import com.pubg.dao.BaseDao;
import com.pubg.entity.ProductType;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class test1 extends BaseDao {

    private Connection conn;
    private PreparedStatement pstmt;
    private ResultSet rs;
    public static void main(String[] args) {
        test1 test1 = new test1();
        for (ProductType productType : test1.list()) {
            System.out.println(productType.toString());
        }
    }

    private List<ProductType> list(){
        List<ProductType> list = new ArrayList<>();
        String sql = "SELECT id,name FROM product_type";
        try{
            conn = openConnection();
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            while (rs.next()){
                ProductType pro = new ProductType(
                    rs.getInt("id"),
                    rs.getString("name")
                );
                list.add(pro);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            closeAll(rs,pstmt,conn);
        }
        return list;
    }
}
